|
|
|
|
|
|
|
Figure 13.11.
Results of SQLVB03.SQV script. |
|
|
|
|
|
|
|
|
The code example in Listing 13.7 introduced a naming convention for indexes. This convention is widely used by SQL programmers. All primary key indexes should start with the letters PK (PKEmployeeID). All keys created for sorting purposes should begin with the letters SK (SKDeptSort). All index keys that require unique values should begin with UK (UKLoginName). All keys that define foreign key relationships should start with FK. (You learn more about foreign keys in the next section.) Finally, any other index keys should start with IK (IKJobTitle) to identify them as index keys. |
|
|
|
|
|
|
|
|
Using the ASC and DESC Keywords in the INDEX Statement |
|
|
|
|
|
|
|
|
You can control the index order by adding ASC (ascending) or DESC (descending) keywords to the CREATE INDEX SQL statement. For example, to create an index on the LastName column, but listing from Zilckowicz to Anderson, you use the following CREATE INDEX statement: |
|
|
|
|
|
|
|
|
CREATE INDEX SKLastName ON NewTable1(LastName DESC); |
|
|
|
|
|
|
|
|
Notice that the DESC goes inside the parentheses. If you want to control the index order on a multiple column index, you can use the following CREATE INDEX statement: |
|
|
|
|
|
|
|
|
CREATE INDEX SKDeptSort ON NewTable1(Department ASC, LastName DESC); |
|
|
|
|
|
|
|
|
If you omit an order word from the CREATE INDEX clause, SQL uses the default ASC order. |
|
|
|
|
|
|
|
|
Using Indexes to Speed Data Access |
|
|
|
|
|
|
|
|
In Listing 13.7, the index SKDeptSort is a special index key. This is a sort key index. Sort key indexes can be used to speed data access while performing single-record lookups (using the Visual Basic Find method), or for speeding report processing by ordering the data before running a list report. Sort key indexes are not used to enforce data integrity rules or perform data entry validation. |
|
|
|
|
|